<?php
namespace Team\Controller;
use Think\Controller;
use Common\Common\JSONHelper as JSONHelper;
class IndexController extends Controller {
	public function index(){
//		$this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>[ 您现在访问的是Home模块的Index控制器 ]</div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');

	}
	public function signUp() {
		$this->display();
	}
	public function login() {
		$this->display();
	}
	public function ballot() {
		$this->display();
	}

	public function reg() {
		$tname = I('request.tname');
		$passwd = I('request.password');
		$existTeam = M('Team');
		$query = $existTeam->where("tname='".$tname."'")->find();
		if(empty($query)) {
			$Team = M('Team');
			$Team->tname = $tname;
			$Team->password = md5($passwd);
			$Team->add();
			JSONHelper::echoJSON(true, JSONHelper::SUCCESS);
		} else {
			JSONHelper::echoJSON(false, JSONHelper::TEAM_EXIST);
		}
	}

	public function dolog() {
		$tname = I('request.tname');
		$passwd = I('request.password');
		$verTeam = M('Team');
		$query = $verTeam->where("tname='".$tname."' AND password='".md5($passwd)."'")->find();
		if(empty($query)) {
			JSONHelper::echoJSON(false, JSONHelper::LOGIN_ERROR);
		} else {
			$oUser = array(
				"tname" => $tname,
				"id" => $query['id']
			);
			session($tname, json_encode($oUser));
			JSONHelper::echoJSON(true, JSONHelper::SUCCESS);
		}
	}

}